/*  
 * Copyright 2007 MBARI 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 */
package org.mbari.timeline;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;

import org.mbari.timeline.model.MultipartEvent;
import org.mbari.timeline.piccolo.Timeline;
import org.mbari.timeline.piccolo.TimelineCanvas;
import org.mbari.timeline.piccolo.TwoPartEventNode;
import org.mbari.timeline.swing.TwoPartEventTable;

import com.domainlanguage.time.Duration;
import com.domainlanguage.time.TimeInterval;
import com.domainlanguage.time.TimePoint;

import edu.umd.cs.piccolox.PFrame;

/** 
 * @author Andrew Chase
 */
public class DemoTimelineAndTableCombined {
	
	final Timeline timeline;
	final TwoPartEventTable table;
	
	public DemoTimelineAndTableCombined(TimePoint start, TimePoint end){
		TimeInterval interval = new TimeInterval(start, true, end, true);
		timeline = new Timeline(interval);
		table = new TwoPartEventTable();
	}
	
	public void addEvent(MultipartEvent twoPartEvent){
		TwoPartEventNode node = new TwoPartEventNode(twoPartEvent, timeline);
		timeline.addEventNode(node);
		table.addEvent(twoPartEvent);
	}

	public static void main(String[] args){
		final DemoTimelineAndTableCombined combined = new DemoTimelineAndTableCombined( //
				DateUtil.BEGIN_2007.plus(Duration.days(1)), DateUtil.BEGIN_2007.plus(Duration.months(1)));

		final MultipartEvent event1 = MultipartEvent.twoPartEvent( //
				DateUtil.BEGIN_2007.plus(Duration.days(3)),
				Duration.minutes(35), Duration.minutes(180));
		event1.setName("ACC");
		final MultipartEvent event2 = MultipartEvent.twoPartEvent( //
				DateUtil.BEGIN_2007.plus(Duration.days(6)),
				Duration.minutes(135), Duration.minutes(280));
		event2.setName("RS");
		final MultipartEvent event3 = MultipartEvent.twoPartEvent( //
            DateUtil.BEGIN_2007.plus(Duration.days(4)),
            Duration.minutes(160), Duration.minutes(170));
		event3.setName("KG");
		
		TimelineCanvas canvas = new TimelineCanvas(combined.timeline);
		final PFrame pFrame = new PFrame("Test Timeline", false, canvas);
		pFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		final JFrame jFrame = new JFrame("Test Table");
		JScrollPane pane = new JScrollPane(combined.table);
		jFrame.getContentPane().add(pane);
		jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		SwingUtilities.invokeLater(new Runnable(){
			public void run() {
				pFrame.setBounds(20, 0, 1000, 350);
				jFrame.setBounds(20, 350, 600, 250);
				pFrame.setVisible(true);
				jFrame.setVisible(true);
				combined.addEvent(event1);
				combined.addEvent(event2);
				combined.addEvent(event3);
			}
		});
	}
}
